package com.cctc.juc.demo.Bitc.Tmp.ADemo;

import java.util.concurrent.TimeUnit;

public class BJoinRunDemo {

    // 效果 2： A、B 顺序执行。

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> print("A"));
        Thread t2 = new Thread(() -> {
            try {
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            print("B");
        });

        t1.start();

        t2.start();
    }

    private static void print(String threadName) {
        for (int i = 1; i <= 3; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(threadName + " -> print: " + i);
        }
    }
}
